package com.xhcl.web.controller.system;

import java.util.ArrayList;
import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.xhcl.common.annotation.Log;
import com.xhcl.common.enums.BusinessType;
import com.xhcl.system.domain.TSrhsPzti;
import com.xhcl.system.domain.TSrhsPzto;
import com.xhcl.system.service.ITSrhsHsxtcsService;
import com.xhcl.system.service.ITSrhsPztiService;
import com.xhcl.common.core.controller.BaseController;
import com.xhcl.common.core.domain.AjaxResult;
import com.xhcl.framework.uitls.poi.ExcelUtil;
import com.xhcl.common.core.page.TableDataInfo;

/**
 * 凭证体Controller
 * 
 * @author xhcl
 * @date 2020-09-02
 */
@Controller
@RequestMapping("/system/pzhz")
public class TSrhsPzhzController extends BaseController
{
    private String prefix = "system/pzhz";

    @Autowired
    private ITSrhsPztiService tSrhsPztiService;
    
    @Autowired
    private ITSrhsHsxtcsService tSrhsHsxtcsService;

    @RequiresPermissions("system:pzhz:view")
    @GetMapping()
    public String pzti(ModelMap mmap)
    {   
    	String year=tSrhsHsxtcsService.getHsxtcsnr("year");
    	String term=tSrhsHsxtcsService.getHsxtcsnr("term");
    	List<String> ndlist=new ArrayList();
    	for (int i=0;i<5;i++) {
    		ndlist.add(String.valueOf(Integer.parseInt(year)-i));
    	}
    	mmap.put("ndlist", ndlist);
    	mmap.put("year", year);
    	List<String> yflist=new ArrayList();
    	for (int i=1;i<=12;i++) {
    		yflist.add(String.valueOf(i));
    	}
    	mmap.put("yflist", yflist);
    	mmap.put("term", term);
        return prefix + "/pzhz";
    }

    /**
     * 查询凭证体列表
     */
    @RequiresPermissions("system:pzhz:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TSrhsPzto tSrhsPzto)
    {   
    	List<TSrhsPzti> list =null;
        startPage();
        if (tSrhsPzto.getParams().get("kmlx")!=null && tSrhsPzto.getParams().get("kmlx").equals("1")) {
        	list =tSrhsPztiService.selectTSrhsPztiHzKmmcList(tSrhsPzto);
        }else {
        	list = tSrhsPztiService.selectTSrhsPztiMxKmmcList(tSrhsPzto);
        }
        return getDataTable(list);
    }

    /**
     * 导出凭证体列表
     */
    @RequiresPermissions("system:pzhz:export")
    @Log(title = "凭证体", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TSrhsPzto tSrhsPzto)
    {
    	List<TSrhsPzti> list =null;
        startPage();
        if (tSrhsPzto.getParams().get("kmlx")!=null && tSrhsPzto.getParams().get("kmlx").equals("1")) {
        	list =tSrhsPztiService.selectTSrhsPztiHzKmmcList(tSrhsPzto);
        }else {
        	list = tSrhsPztiService.selectTSrhsPztiMxKmmcList(tSrhsPzto);
        }
        ExcelUtil<TSrhsPzti> util = new ExcelUtil<TSrhsPzti>(TSrhsPzti.class);
        return util.exportExcel(list, "pzti");
    }

   
}
